<%@page import="java.util.List"%>
<%@page import="com.situ.personal.entity.User"%>
<%@page import="com.situ.personal.entity.PageInfo"%>
<%@page import="java.util.ArrayList"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<link rel="stylesheet" type="text/css" href="bootstrap-3.3.7-dist/css/bootstrap.css"/>
</head>
<body>
	<%
	   // jsp页面中内置了request对象，可以直接使用,类似于document可以直接使用
		PageInfo pageInfo = (PageInfo)request.getAttribute("pageInfo");
	%>
	
	
	<%-- <a class="btn btn-primary" href="<%=request.getContextPath()%>/user_insert.jsp">添加</a> --%>
	<a class="btn btn-primary" href="<%=request.getContextPath()%>/user?method=getUserInsertPage">添加</a>
	<table class="table table-striped table-bordered table-hover table-condensed">
		<tr>
			<th>ID</th>
			<th>名字</th>
			<th>年龄</th>
			<th>密码</th>
			<th>邮箱</th>
			<th>部门ID</th>
			<th>删除</th>
			<th>修改</th>
		</tr>
		<%
			
			List<User> list = pageInfo.getList();
			for (User user : list) {
		%>
				<tr>
					<td><%=user.getId()%></td>
					<td><%=user.getName()%></td>
					<td><%=user.getAge()%></td>
					<td><%=user.getPassword()%></td>
					<td><%=user.getEmail()%></td>
					<td><%=user.getDepartmentId()%></td>
					<td><a href="javascript:void(0)" onclick="deleteById(<%=user.getId()%>)">删除</a></td>
					<td><a href="<%=request.getContextPath()%>/user?method=selectById&id=<%=user.getId()%>">修改</a></td>
				</tr>
		<%
		    }
		%>
				
	
	</table>
	
	<nav aria-label="Page navigation">
	  <ul class="pagination">
	  <% 
	  if(pageInfo.getPageNo() == 1){
	  %>
	     <li class = "disabled">
	  
	      <a href="#" aria-label="Previous">
	        <span aria-hidden="true">&laquo;</span>
	      </a>
	     </li>
	    <%
	    }
	    else{
	    %>
	     <li>
	  
	      <a href="<%=request.getContextPath()%>/user?method=findByPage&pageNo=<%=pageInfo.getPageNo() - 1%>" aria-label="Previous">
	        <span aria-hidden="true">&laquo;</span>
	      </a>
	     </li>
	     <%
	     }
	     %>
	     <%
	    	int totalPage = pageInfo.getTotalPage();
	        int pageNo = pageInfo.getPageNo();
	    	for(int i = 1; i<= totalPage; i++) {
	    		if(pageNo == i){
	     %>
	    			<li  class = "active"><a  href=""><%=i%></a></li>
	     <%
	    		
	    		}else{
	    %>
	    			<li><a href="<%=request.getContextPath()%>/user?method=findByPage&pageNo=<%=i%>"><%=i%></a></li>
	    <% 			
	    		}
	  
	    		
	    	}
	    %>
	     <% 
	  if(pageInfo.getPageNo() == pageInfo.getTotalPage()){
	  %>
	     <li class = "disabled">
	  
	      <a href="#" aria-label="Next">
	        <span aria-hidden="true">&raquo;</span>
	      </a>
	     </li>
	    <%
	    }
	    else{
	    %>
	     <li>
	  
	      <a href="<%=request.getContextPath()%>/user?method=findByPage&pageNo=<%=pageInfo.getPageNo() + 1%>" aria-label="Next">
	        <span aria-hidden="true">&raquo;</span>
	      </a>
	     </li>
	     <%
	     }
	     %>
	  </ul>
	</nav>
	
	<script type="text/javascript">
		function deleteById(id) {
			var isDel = confirm("您确认要删除么？");
			if (isDel) {
				location.href = "/Java1912WebPersonal/user?method=deleteById&id=" + id;
			}
		}
	</script>
</body>
</html>